#include "comm.hpp"

int main()
{
    Init init;

    int fd = open(PATHNAME, O_CREAT | O_RDONLY, MODE);
    if(fd < 0)
    {
        perror("client.cc::fd::main::open");
        return 1;
    }

    int fdin = open("file.txt", O_CREAT | O_WRONLY, MODE);
    if(fd < 0)
    {
        perror("client.cc::fdin::main::open");
        return 1;
    }

    char buffer[SIZE] = {0};
    while(true)
    {
        buffer[0] = '\0';
        //printf("");
        ssize_t s = read(fd, buffer, sizeof(buffer));
        if(s > 0)
        {
            buffer[s] = '\0';
            write(fdin, buffer, sizeof(buffer));
            printf("copy complete!\n");
        }
        else if(s == 0)
        {
            printf("process normal quit!!\n");
            break;
        }
        else
        {
            printf("process error quit!!\n");
            break;
        }
    }

    close(fd);
    close(fdin);
    return 0;
}